<ul id='reservation-ul'>
  <?php foreach($data['reservations'] as $k1=>$v1): ?>
    <li class='reservation-li' id="reservation_<?php echo $v1->chr_id; ?>">
    <span class='reservation-li-row'>  Date début :   <span class='datedeb'><?php echo $v1->chr_datedeb; ?></span>   </span>
    <span class='reservation-li-row'>  Date fin :     <span class='datefin'><?php echo $v1->chr_datefin; ?></span>   </span>
    <span class='reservation-li-row'>   Locataire :   <span class='commentaire'><?php echo $v1->chr_loca; ?> <?php echo $v1->chr_firstname; ?></span>     </span>
    <span class="reservation-delete"><img src="<?php echo $data['baseurl']; ?>global/img/globalbo/appartements/delete-128.png" style="vertical-align: middle; margin-left: 5px;"></span>
    <input type="hidden" name="prenom" class="prenom" value="<?php echo $v1->chr_firstname; ?>">
    <input type="hidden" name="daten" class="daten" value="<?php echo $v1->chr_daten; ?>">
    <input type="hidden" name="lieun" class="lieun" value="<?php echo $v1->chr_lieun; ?>">
    <input type="hidden" name="dateentree" class="dateentree" value="<?php echo $v1->chr_entree; ?>">
    <input type="hidden" name="adresse" class="adresse" value="<?php echo $v1->chr_addr; ?>">
    <input type="hidden" name="dept" class="dept" value="<?php echo $v1->chr_dept; ?>">
    <input type="hidden" name="ville" class="ville" value="<?php echo $v1->chr_ville; ?>">
    </li>
  <?php endforeach; ?>
</ul>

<script type="text/javascript">
/** Show reservation detail **/

var delet = false;
$(".reservation-delete").click(function(){
  if(!confirm("Êtes-vous sûr de vouloir supprimer la réservation ?"))
    return;
  var li = $(this).parent("li");
  var id = li.attr('id').replace('reservation_', '');
  li.fadeOut("slow");
  emptyReservation();
  $('#component-change-reservation-form-indicator').val("new");
  url="<?php echo $data['baseurl']; ?>admin/frbFlat/frbFlat_MainController/appartements";
  $.ajax({
    urlApp: url,
    type: 'POST',
    cache: false,
    data: "del_reservation=true&reservation_id="+id,
    success: function(html){
      //alert(html);
    }
  });  
  delet = true;
  //alert(id);
});

$('.reservation-li').click(function(){
  if(delet){
    delet = false;
    return;
  }
  emptyReservation();
  var datedeb = $(this).children('.reservation-li-row:eq(0)').children('.datedeb').html();
  var datefin = $(this).children('.reservation-li-row:eq(1)').children('.datefin').html();
  if(datefin == "00/00/0000"){
    datefin="";
  }
  var commentaire = $(this).children('.reservation-li-row:eq(2)').children('.commentaire').html();
  var id = $(this).attr('id').replace('reservation_', '');
  var prenom = $(this).children(".prenom").val();
  var daten = $(this).children(".daten").val();
  var lieun = $(this).children(".lieun").val();
  var dateentree = $(this).children(".dateentree").val();
  var dept = $(this).children(".dept").val();
  var adresse = $(this).children(".adresse").val();
  var ville = $(this).children(".ville").val();

  $('#component-change-reservation-form-datedeb').val(datedeb);
  $('#component-change-reservation-form-datefin').val(datefin);
  $('#component-change-reservation-form-locataire').val(commentaire);
  $('#component-change-reservation-form-chambreres').val(id);
  $('#component-change-reservation-form-prenom').val(prenom);
  $('#component-change-reservation-form-daten').val(daten);
  $('#component-change-reservation-form-lieun').val(lieun);
  $('#component-change-reservation-form-date_entree').val(dateentree);
  $('#component-change-reservation-form-dept').val(dept);
  $('#component-change-reservation-form-adresse').val(adresse);
  $('#component-change-reservation-form-ville').val(ville);
  $('#component-change-reservation-form-indicator').val("change");
});

</script>